//
//  HLMainViewController.swift
//  HL-sinaWeiBo
//
//  Created by 任翰林 on 16/5/11.
//  Copyright © 2016年 任翰林. All rights reserved.
//

import UIKit

class HLMainViewController: UITabBarController {
    

    
    
//    let homeVC = HLHomeTableViewController()

    override func viewDidLoad() {
        super.viewDidLoad()

//        self.tabBar = HLTabBar()//把自定义的tabbar赋值给属性tabbar
        let hlTabbar = HLTabBar()
//        使用KVC,设置只读属性
        setValue(hlTabbar, forKey: "tabBar")
        
        hlTabbar.composeButtonClousre = {[weak self] in
        
            print("翰林，我是加号按钮，我二笔点击了，这是闭包方法，这是外界控制器的方法,")
            print(self)
         
        }
        
        
        addChildViewController(HLHomeTableViewController(), title: "首页" , imageName: "tabbar_home")
        addChildViewController(HLDiscoverTableViewController(), title: "发现" , imageName: "tabbar_discover")
        addChildViewController(HLMessageTableViewController(), title: "信息" , imageName: "tabbar_message_center")
        addChildViewController(HLPeofileTableViewController(), title: "我的" , imageName: "tabbar_profile")
        
    }
    
  

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    
    
    func addChildViewController(childController: UIViewController, title: String , imageName: String) {
//        设置全局的统一的选中颜色，这句代码执行的越早越好，甚至可以考虑放到appdelegate上面
        UITabBar.appearance().tintColor = UIColor.orangeColor()
        
//        childController.tabBarItem.title = title
//        childController.navigationItem.title = title
//        统一修改title
        childController.title = title
//
        childController.tabBarItem.image = UIImage(named: imageName)
        childController.tabBarItem.selectedImage = UIImage(named: imageName + "_selected")
        
//        扩展实验
//        设置带文字的图片
//        childController.tabBarItem.image = UIImage(named: "allproducts")
//        childController.tabBarItem.selectedImage = UIImage(named: "allproducts_s")
//        childController.tabBarItem.imageInsets = UIEdgeInsets(top: 5, left: 0, bottom: -5, right: 0)

//        修改图片的渲染方式
//        childController.tabBarItem.selectedImage = UIImage(named: imageName + "_selected")?.imageWithRenderingMode(.AlwaysOriginal)
//        修改文字颜色
//        childController.tabBarItem.setTitleTextAttributes([NSForegroundColorAttributeName: UIColor.orangeColor()], forState: .Selected)
//        设置文字打下
         childController.tabBarItem.setTitleTextAttributes([NSFontAttributeName: UIFont.systemFontOfSize(14)], forState: .Normal)
        
        
        let nav = UINavigationController(rootViewController: childController)
        addChildViewController(nav)
        
    }
    
    

    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
        // Get the new view controller using segue.destinationViewController.
        // Pass the selected object to the new view controller.
    }
    */

}
